/*
	文件复制1
		input, err := ioutil.ReadFile(srcFileNmae)
		err = ioutil.WriteFile(dstFileName, input, 0644)

	文件复制2
		source, _ := os.Open(srcFileName)
		destinatino, _ := os.OpenFile(dstFileName, os.O_CREATE|os.O_WRONLY, 0666)
		n, err := source.Read(buf)
		destination.Write(buf[:n])
*/

package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	// input, err := ioutil.ReadFile("./wtext.txt")
	// if err != nil {
	// 	fmt.Println(err)
	// 	return
	// }
	// err = ioutil.WriteFile("./wtext2.txt", input, 0644)

	var buf = make([]byte, 2)
	source, _ := os.Open("./wtext.txt")
	defer source.Close()
	destination, _ := os.OpenFile("./wtext2.txt", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
	for {
		n, err := source.Read(buf)
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Println(err)
			return
		}
		destination.Write(buf[:n])
	}

}
